package com.hopu.blb_erp.controller;

import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.entity.TLogistics;
import com.hopu.blb_erp.service.LogsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api
@RestController
public class LogsController {

    @Autowired
    private LogsService logsService;

    @ApiOperation("查询所有的物流公司,分页")
    @GetMapping("/logistics/{current}/{pageSize}")
    public ResponseEntity<PageEntity> findPage(@PathVariable("current")Integer current, @PathVariable("pageSize")Integer pageSize,
                                               String logisticsName){
        PageEntity<TLogistics> pages = logsService.findLogsPages(current, pageSize,logisticsName);
        return ResponseEntity.ok(pages);
    }

    @ApiOperation("查询所有物流公司信息")
    @GetMapping("/logistics")
    public ResponseEntity<List<TLogistics>> findAllLogs(){
        List<TLogistics> logistics = logsService.findAllLogs();
        return ResponseEntity.ok(logistics);
    }

    @ApiOperation("对物流公司进行更新")
    @PostMapping("/logistic")
    public ResponseEntity<String> maLogs(@RequestBody TLogistics logistics){
        logsService.saveOrUpdate(logistics);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("根据id进行删除物流公司")
    @DeleteMapping("/logistic/{id}")
    public ResponseEntity<String> removeLogs(@PathVariable Integer id){
        logsService.removeById(id);
        return ResponseEntity.ok("ok");
    }
}
